home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / modem / tlxtw202.zip / TWLOGOFF.SLT < prev    next >
Text File  |  1994-05-05  |  19KB  |  513 lines

  1.   //-----------------------------------------------------------------------//
  2.  //                         Twlogoff.slt  Alt-F5                          //
  3. //-----------------------------------------------------------------------//
  4. //      Twlogoff.slt  Alt-F5
  5. //
  6. //      Lines beginning with "//" are comments and ignored by the
  7. //      script compiler
  8. //
  9. //      Congratulations!  You have been recruited into the wonderful
  10. //      world of Telix SALT programming.  This file requires editing
  11. //      to work properly.
  12. //
  13. //      This script requires editing for each particular BBS that
  14. //      you play on. You only need to edit three small sections:
  15. //      1.  do_bbs() function
  16. //      2.  Offline_maintenance() function
  17. //      3.  comment out line 363 (approximatelly)
  18. //
  19. //      Each section is commented describing what it does.
  20. //
  21. //      What this script does:
  22. //
  23. //      This script will be called from DNINTG (Ctrl-D, Download
  24. //      Interrogation Reports) or CIM_WARP (Ctrl-L, Level Diagram
  25. //      Generator) if you choose to do so.
  26. //
  27. //      It exits Tradewars from the "Command [TL=" prompt, (cloaks
  28. //      or remains on a planet) then logs off the BBS and runs CRAI
  29. //      and anything else you want to do. (Can be run offline if you
  30. //      just want to do the offline stuff) You can run Ctrl-D and
  31. //      gather all the reports and after its finished it will call
  32. //      this script that will log you off the BBS and do any
  33. //      maintenance you want to do, all automatically.
  34. //
  35. //      After editing this file it must be re-compiled using Telix's script
  36. //      compiler (CS.EXE).
  37. //      Type "CS Twlogoff" at the dos prompt.
  38. //
  39. ///////////////////////////////////////////////////////////////////////////////
  40. str f1[64],buf[255],drs[3],tmpbuf[30],
  41.     bbsname[8],shortname[3],
  42.     planet_remain[64],planet_no[5],
  43.     gamedir[64];
  44. int a, b, c, dr, f, fd, fs, h, i, l, s, x, y,
  45.     stat, t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,
  46.     tm, chrcolor, statline, statline_color,
  47.     old_chk_key, key = 0;
  48.   //-----------------------------------------------------------------------//
  49.  //                  do_bbs()              // Edit below                  //
  50. //-----------------------------------------------------------------------//
  51. do_bbs()              // Edit below
  52. {
  53.  if ( !carrier() ) return 0;
  54.  substr( _entry_name, 0, 4, bbsname); strupper( bbsname );
  55. //-----------------------------------------------------------------------//
  56. //  Enter the first four characters from the BBS in all CAPITOL LETTERS below.
  57. //  followed by the prompts that will get you off the BBS.
  58. //
  59. //      This is what must be done after you see the "Returning to BBS"
  60. //      message to get you off the BBS.
  61. //
  62. //       first 4 chars of BBS name from the dialing directory. (all CAPS)
  63. //             │
  64. //             └───┬──┐         whatever gets you off (the BBS).
  65. //                 │  │    ┌──────────────────────────────────────────┐
  66. //                 │  │    │                                          │
  67. //-----------------------------------------------------------------------//
  68.  if     (bbsname=="TEST")  return -2;
  69.  
  70.  else if(bbsname=="XXXX") {  // first 4 characters of the bbs name
  71.                              //
  72.     waitfor("XXXX"  ,30);    // prompt from the bbs, after you see the
  73.                              // "Returning to BBS" message"
  74.                              // usually it will be something from
  75.                              // the door's menu that the bbs displays.
  76.                              //
  77.     delay_scr(1);            // delay 1/10 second.
  78.                              //
  79.     cputs("XXXX");           // what you type go logoff the bbs.
  80.                              //
  81.     cputc( 13 );             // send a carriage return
  82.  }
  83.  
  84.  else if(bbsname=="CAST") {
  85.     waitfor("Y Z Q"  ,30);delay_scr(2);cputs("Q");
  86.     waitfor("O A K"  ,30);delay_scr(2);cputs("G");
  87.     waitfor("[Y/n]"  ,30);delay_scr(2);cputs("^M");
  88.  }
  89.  
  90.  else if(bbsname=="CHES"){
  91.     waitfor("Global" ,10);delay_scr(10);cputs("--!!");
  92.     //_script_dir="c:\telix\work\slc\";
  93.     //while(carrier())terminal();
  94.     //call("movchess","c:\telix\work\dl\chessb.???");
  95.     //_script_dir="c:\telix\work\slc\slt\tlxtw\";
  96.  }
  97.  
  98.  else if(bbsname=="TERM"){
  99.     waitfor("Menu"  ,30);delay_scr(10);cputs("Q-");
  100.  }
  101.  
  102.  else if(bbsname=="ROBI") {
  103.     waitfor("@ *]?" ,60);delay_scr(1);cputs("Q");
  104.     waitfor("Menu"  ,60);delay_scr(1);cputs("GY");
  105.  }
  106.  
  107.  else {
  108.     soft_wind("BBSname not defined in TWLogoff.slt", 40 );
  109.     return -3;
  110.  }
  111.  delay_scr(10);
  112.  drf();
  113.  return 0;
  114. }
  115. // end of do_bbs()
  116. //-----------------------------------------------------------------------//
  117. //                  Offline_maintenance() // Edit below                  //
  118. //  This section does all the offline maintenance.                       //
  119. //  You can delete anything you want or add more here.                   //
  120. //-----------------------------------------------------------------------//
  121. Offline_maintenance() // Edit below
  122. {
  123.    if ( carrier() ) hangup();
  124.    capture("*close*");
  125.  
  126.    printsc("^M^J─────────────── *  *  *  TLXTW Offline Maintenance  *  *  *  ───────────────");
  127.  
  128.     printsc("^M^JFcopy - " );               // copy cap file to game's dir
  129.     printsc( _capture_fname );
  130.     printsc( " " );
  131.     printsc( gamedir );
  132.     printsc( "cap" );
  133.     buf="d:\cap";
  134.     if(filefind(buf,0,tmpbuf)) {
  135.           newdir( gamedir );
  136.           fcopy(buf, "cap" );
  137.           fdelete(buf);
  138.     }
  139.  
  140.     printsc("^M^Jcrai " );                  // run crai
  141.     call("crai");
  142.  
  143.     newdir( gamedir );
  144.     fdelete("twassist.cim");                // delete unnecessary files
  145.     fdelete("twacimup.ptr");
  146.     //delete("*.bak");
  147.  
  148.     if(filefind("Twassist.dat",0,buf)) {    // modify twassist(c) database
  149.         buf="Twassist Twassist /a ME,cap, save_db";
  150.         prints("");
  151.         printsc(buf);
  152.         if(write_batch_file(buf))
  153.             exittelix(100,0);
  154.     }
  155.     call("hangup");
  156.     newdir( _telix_dir );
  157.     return 1;
  158. }//end of Offline_maintenance()
  159.   //-----------------------------------------------------------------------//
  160.  //      write_batch_file(str line1, str line2, str path, str rfname)     //
  161. //-----------------------------------------------------------------------//
  162. write_batch_file(str line1)
  163. {
  164.     str fname[64];
  165.     if(!getenv("temp",fname)) {
  166.         soft_wind("TEMP environment variable not found.",30);
  167.         return 0;
  168.     }
  169.     append_backslash(fname);
  170.     strcat(fname,"twaauto.bat");
  171.  
  172.     if((f=fopen(fname,"w"))==0) {
  173.         fclearerr(f);
  174.         buf="Open Error ";
  175.         strcat(buf,fname);
  176.         soft_wind(buf,50);
  177.         return 0;
  178.     }
  179.     fputs("@echo off^m^j",f);
  180.     fputs(line1 ,f);
  181.     fclose(f);
  182.     return 1;
  183. }
  184.   //-----------------------------------------------------------------------//
  185.  //                     append_backslash( str string )                    //
  186. //-----------------------------------------------------------------------//
  187. append_backslash( str string )
  188. {
  189.    if(subchr(string,strlen(string)-1)!='\')strcat(string,"\");
  190.    return string;
  191. }
  192.   //-----------------------------------------------------------------------//
  193.  //                                 drf()                                 //
  194. //-----------------------------------------------------------------------//
  195. drf()
  196. {
  197.     int osk;
  198.     osk=_scr_chk_key;_scr_chk_key=0;
  199.     while( (c=cgetct(dr)) > -1 ) {
  200.       if(inkey()==27) {
  201.         _scr_chk_key=osk;
  202.         return 0;
  203.       } printsc_trm(c);
  204.     } _scr_chk_key=osk;
  205.     return 1;
  206. }
  207.   //-----------------------------------------------------------------------//
  208.  //                  soft_wind(str message, int duration)                 //
  209. //-----------------------------------------------------------------------//
  210. soft_wind(str message, int duration)
  211. {
  212.     int old_chk_key;
  213.     old_chk_key = _scr_chk_key;
  214.     _scr_chk_key = 0;
  215.     int l, h, x, y, key = 0, ts;
  216.     cursor_onoff(0);
  217.     x=getx(); y=gety();
  218.     l = strlen(message)/2;
  219.     h = vsavearea(37-l, 10, 43+l, 14);
  220.     box(37-l, 10, 43+l, 14, 3, 0, 5 );
  221.     pstraxy(message, 40-l  , 12, 11 );
  222.     ts = timer_start(duration);
  223.     while( !key && !time_up(ts)) key=inkey();
  224.     vrstrarea(h);
  225.     cursor_onoff(1);
  226.     gotoxy(x,y);
  227.     timer_free(ts);
  228.     _scr_chk_key = old_chk_key;
  229.     return key;
  230. }
  231.   //-----------------------------------------------------------------------//
  232.  //                       fill_spaces( str bbsbuf )                       //
  233. //-----------------------------------------------------------------------//
  234. fill_spaces( str bbsbuf )
  235. {
  236.     int i;
  237.     str chr[1];
  238.     int count = 0;
  239.     while (count < 8) {
  240.         if      (count == 0) chr = ".";
  241.         else if (count == 1) chr = "+";
  242.         else if (count == 2) chr = " ";
  243.         else if (count == 3) chr = "?";
  244.         else if (count == 4) chr = "*";
  245.         else if (count == 5) chr = "/";
  246.         else if (count == 6) chr = "\";
  247.         i=0;
  248.         while (1) {
  249.             i = strpos(bbsbuf, chr, i);
  250.             if (i == -1) break;
  251.             setchr(bbsbuf, i ,'_');
  252.             i = i + 1;
  253.         } ++count;
  254.     } return bbsbuf;
  255. }
  256.   //-----------------------------------------------------------------------//
  257.  //                        chk_stat ( int statchk )                       //
  258. //-----------------------------------------------------------------------//
  259. chk_stat ( int statchk )
  260. {
  261.     gotoxy(67, statchk);
  262.     if((vgetchr() & 255)== 79){Statline=statchk;statline_color=vgetchr()/256;}
  263.     else return(-1);
  264. }
  265.   //-----------------------------------------------------------------------//
  266.  //                         chk_prompt(str prompt)                        //
  267. //-----------------------------------------------------------------------//
  268. chk_prompt(str prompt)
  269. {
  270.     str promptbuf[20];
  271.     int l,h,key,osk,retval;
  272.  
  273.     osk=_scr_chk_key;
  274.     _scr_chk_key=0;
  275.     cursor_onoff(0);
  276.     l=strlen(prompt);
  277.     x=getx();y=gety();
  278.     vgetchrs(0,y,promptbuf,0,l);
  279.     gotoxy(x,y);
  280.     if(strcmpi(prompt,promptbuf)==0)
  281.       retval=1;
  282.     else retval=0;
  283.     cursor_onoff(1);
  284.     _scr_chk_key=osk;
  285.     return retval;
  286. }
  287.   //-----------------------------------------------------------------------//
  288.  //                         delete( str filename )                        //
  289. // delete ( "d:\*.bak" ); delete all .txt files on drive d:              //
  290. //-----------------------------------------------------------------------//
  291. delete( str filename )
  292. {
  293.     str     buf[64];
  294.     int     y;
  295.  
  296.     fnstrip( filename, 12, buf );
  297.     if(strlen(buf))
  298.         newdir( buf );
  299.     printsc("^m^jDelete Filemask:  " ); printsc( filename );
  300.     if ( !filefind( filename, 0, buf )) {
  301.         prints("");
  302.         printsc( "No matching files.");
  303.         newdir( _telix_dir );
  304.         return 0;
  305.     }
  306.     while( filefind( filename, 0, buf ) ) {
  307.         prints("");
  308.         y = gety();
  309.         if ( fdelete( buf ) == -1 ) {
  310.             printsc( buf );
  311.             gotoxy( 18, y );
  312.             printsc( "Error deleting." );
  313.         }
  314.         else {
  315.             printsc( buf );
  316.             gotoxy( 18, y );
  317.             printsc("Deleted.");
  318.         }
  319.         filename = "";
  320.     }
  321.     newdir( _telix_dir );
  322.     return 0;
  323. }
  324. str    Buffer[16384];
  325.   //-----------------------------------------------------------------------//
  326.  //                   fcopy(str Infname, str Outfname )                   //
  327. //-----------------------------------------------------------------------//
  328. fcopy(str Infname, str Outfname )
  329. {
  330.  str fsbuf[10], fps[12];
  331.  int a, b, fs, fp, h, i, g, gpos, l,
  332.      text_color = 15,
  333.      box_color  =  1,
  334.      hi_color   = 30,
  335.      lo_color   =  7,
  336.      Infile, Outfile, BytesRead;
  337.  cursor_onoff(0);
  338.  a = 20; b =  8; gpos = a+2;
  339.  h = vsavearea( a-18, b-1,a+58,b+7 ); box(  a-18 ,b-1,a+58,b+7, 2, 0,box_color);
  340.  pstraxy( "╡", a+44, b-1,box_color);pstra(" Fcopy ",text_color);pstra("╞",box_color);
  341.  pstraxy("From :  ", a+2,b+1,text_color); pstra( Infname , lo_color);
  342.  pstraxy("To   :  ", a+2,b+2,text_color); pstra( Outfname, lo_color);
  343.  pstraxy("Bytes:  ", a+2,b+3,text_color);
  344.  pstraxy("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░", a+2,b+6,31);
  345.  fs = filesize( Infname );  itos( fs, fsbuf );
  346.  if ( (Infile=fopen(Infname, "r")) != -1 ) {
  347.    if ( (Outfile=fopen(Outfname, "w")) != -1 ) {
  348.       while ( !feof(Infile) ) {
  349.       Bytesread = fread(Buffer, 16384, Infile);
  350.       /////////////////////// Bytes, Percentage, Bar Graph /////////////////////
  351.       fp =    ftell(Infname);
  352.       if (fp == 0) fp = 1;
  353.       itos(fp, fps); pstraxy(fps, a+10, b+3,lo_color);           //  bytes of
  354.       pstra(" of ",lo_color); pstra(fsbuf,lo_color); pstra(" bytes",lo_color);  //  bytes
  355.       g = fp * 35 / fs;                     //  graph
  356.       // fp = fp * 100 / fs; itos(fp, fps);             //    %
  357.       for(i = gpos; i <= gpos + g; ++i) pstraxy("▓", i, b+6, 14);// graph
  358.       // pstraxy(fps, a+18, b+4, 30); pstra(" %", 30);          //  %
  359.       /////////////////////////////////////////////////////////////////////////////
  360.       fwrite(Buffer, BytesRead, Outfile);
  361.      } fclose(Outfile);
  362.    } fclose(Infile);
  363.  } cursor_onoff(1);vrstrarea(h);
  364. }
  365.   //-----------------------------------------------------------------------//
  366.  //                           Remain_on_Planet()                          //
  367. //-----------------------------------------------------------------------//
  368. Remain_on_Planet()
  369. {
  370.     int tlimit;
  371.     track_free(0);
  372.     t1 = track("abort", 0);
  373.     t2 = track("Planet command", 0);
  374.     t3 = track("turning to", 0);
  375.     t4 = track("not in this", 0);
  376.     tlimit=timer_start(600);
  377.     cputs("L");
  378.     while( carrier() && inkey()!=27 ) {
  379.         terminal();stat=track_hit(0);
  380.         if(time_up(tlimit)) {track_free(0);return -1;}
  381.         else if(!stat) continue;
  382.         else if (stat == t1) {
  383.             track_free(t1); delay_scr(dr); cputs(planet_no);
  384.             if ( stoi( planet_no) < 200 ) cputc(13);
  385.         }
  386.         else if (stat == t2) {
  387.             track_free(t2); cputs("C");
  388.             if ( chrcolor == 5 ) cputs(" ");
  389.             cputs("RYY");
  390.             if ( chrcolor == 5 ) cputs(" ");
  391.         }
  392.         else if (stat == t3)   break;
  393.         else if (stat == t4) {track_free(0); return -1;}
  394.     }
  395.     timer_free(tlimit);
  396.     track_free(0);
  397.     return 1;
  398. }
  399.   //-----------------------------------------------------------------------//
  400.  //                                 main()                                //
  401. //-----------------------------------------------------------------------//
  402. main()
  403. {
  404.     ///////////////////////////////////////////////////////////////////////////
  405.     // Delete this line after you have edited do_bbs() and Offline_maintenance()
  406.     // above.  This is the only line you have to edit in this section.
  407.     // --------------------------------
  408.     //  registration
  409.     //  soft_wind("You must edit TWLOGOFF.SLT first", 50 ); return -1;
  410.     //  registration
  411.     // --------------------------------
  412.     ///////////////////////////////////////////////////////////////////////////
  413.     old_chk_key=_scr_chk_key;_scr_chk_key=0;
  414.     update_term();
  415.     if(!getenv("f1",f1)) {
  416.         soft_wind("F1 environment variable not found",25);
  417.         _scr_chk_key=1;
  418.         return(-1);
  419.     }
  420.     append_backslash(f1);
  421.     if(!getenv("Temp",planet_remain)) {
  422.         soft_wind("TEMP environment variable not found",25);
  423.         _scr_chk_key=1;
  424.         return(-1);
  425.     }
  426.     append_backslash(planet_remain);
  427.     strcat( planet_remain, "planet.tmp" );
  428.     if(!getenv("dr",drs)) {
  429.         soft_wind("DR environment variable not found", 25);
  430.         _scr_chk_key=1;
  431.         return(-1);
  432.     }
  433.     dr=stoi(drs);
  434.     if(!strlen(_entry_name))
  435.         if(call("bbsname")==-1) {_scr_chk_key=1;return(-1);}
  436.     bbsname=_entry_name;
  437.     strcat(f1,fill_spaces(bbsname));
  438.     if(!filefind(f1,16,buf))
  439.         if(call("bbsname")==-1) {_scr_chk_key=1;return(-1);}
  440.     append_backslash(f1);
  441.     gamedir=f1;
  442.     x=getx();y=gety();if(chk_stat(0)==-1)chk_stat(24);gotoxy(x,y);
  443.     x=getx();y=gety();
  444.     pstraxy("Calling Twlogoff                                      │",0,statline,statline_color);
  445.     pstraxy(_entry_name,17,statline,statline_color);
  446.     gotoxy(x,y);
  447.     substr(bbsname,0,3,shortname);
  448.     delay_scr(dr);
  449.     if(carrier()) {
  450.         if(!chk_prompt("Command [TL")) {
  451.             delay_scr(20);
  452.             drf();
  453.         }
  454.         if(!chk_prompt("Command [TL") < 0 ){
  455.             soft_wind("Must be at the ^0034Command [TL=^0034 prompt.",25);
  456.             return(-1);
  457.         }
  458.     }
  459.     if(filefind(planet_remain,0,buf)) {
  460.         if((f=fopen(planet_remain,"r"))!=0) {
  461.             a=0;
  462.             while(!feof(f)) {
  463.                 fgets(buf,64,f);
  464.                 ++a;
  465.                 if(a==1) {
  466.                 //    strupper( buf );
  467.                 //    substr(_entry_name,0,strlen(_entry_name),tmpbuf);
  468.                 //    strupper(tmpbuf);
  469.                 //    if((strcmpi(buf,tmpbuf))!=0) {
  470.                 //        prints("");
  471.                 //        pstra("Entryname doesn't match Planet.tmp file",7);
  472.                 //        prints("");
  473.                 //        pstra("_Entry_name= ",7);pstra(tmpbuf,7);
  474.                 //        prints("");
  475.                 //        pstra("Planet.tmp = ", 7);pstra(buf,7);
  476.                 //        prints("");
  477.                 //        fclose(f);
  478.                 //        return -1;
  479.                 //    }
  480.                 } planet_no = buf;
  481.             }
  482.         } fclose(f);fdelete(planet_remain);
  483.     }
  484.     if(planet_no) {
  485.         f=Remain_on_Planet();
  486.         if(f<0) {_scr_chk_key=old_chk_key;return -1;}
  487.     }
  488.     else {
  489.         t1 = track("med? (Y/N)?", 0);
  490.         t2 = track("king Device?", 0);
  491.         t3 = track("turning to", 0);
  492.         _scr_chk_key=1;
  493.         cputs("Q");
  494.         while(carrier() && inkey() != 27 ) {
  495.             terminal();stat=track_hit(0);if(!stat)continue;
  496.             else if(stat==t1){track_free(t1);delay_scr(dr);cputs("Y");}
  497.             else if(stat==t2){track_free(t2);delay_scr(dr);cputs("Y");}
  498.             else if(stat==t3){
  499.                 track_free(0);
  500.                 capture("*close*");
  501.                 _scr_chk_key=old_chk_key;
  502.                 break;
  503.             }
  504.         }
  505.     }
  506.     i=do_bbs();
  507.     if(i==-2||i==-3) return i;
  508.     drf();
  509.     Offline_maintenance();
  510.     _scr_chk_key=old_chk_key;
  511.     return 0;
  512. }
  513.